# coding: utf-8
from studio.models import *
from django.contrib import admin
from django.contrib.flatpages.admin import FlatPageAdmin
from django.contrib.flatpages.models import FlatPage
from markitup.widgets import AdminMarkItUpWidget
from modeltranslation.admin import TranslationAdmin

class PhotoMainAdmin(admin.ModelAdmin):
    list_display = ('picture', 'type')

class GoodInline(generic.GenericStackedInline):
    model = Good
    extra = 5
    exclude = ['title_ru',]

class CollectionInline(admin.StackedInline):
    model = CollectionImg
    readonly_fields=['picture',]
    fields = ['picture','img',]
    extra = 5

class CollAdmin(admin.ModelAdmin):
    list_display = ('title',)
    inlines = [GoodInline]
    exclude = ['title_ru',]
class CollectionAdmin(admin.ModelAdmin):
    list_display = ('title', 'year')
    inlines = [CollectionInline]
    exclude = ['title_ru',]

class NewsAdmin(admin.ModelAdmin):
    list_display = ('title','date','public')
    exclude = ['anounce_ru','text_ru']
    def formfield_for_dbfield(self, db_field, **kwargs):
        if db_field.name in ('anounce', 'anounce_ru','anounce_en','text', 'text_ru','text_en'):
            kwargs['widget'] = AdminMarkItUpWidget()
        return super(NewsAdmin, self).formfield_for_dbfield(db_field, **kwargs)

class MarkItUpFlatPageAdmin(FlatPageAdmin, TranslationAdmin):
    def formfield_for_dbfield(self, db_field, **kwargs):
        if db_field.name == 'content':
            kwargs['widget'] = AdminMarkItUpWidget()
        field = super(MarkItUpFlatPageAdmin, self).formfield_for_dbfield(db_field, **kwargs)
        self.patch_translation_field(db_field, field, **kwargs)
        return field

admin.site.unregister(FlatPage)
admin.site.register(FlatPage, MarkItUpFlatPageAdmin)
admin.site.register(PhotoMain, PhotoMainAdmin)
admin.site.register(MenGoodClass, CollAdmin)
admin.site.register(WomenGoodClass, CollAdmin)
admin.site.register(DecorGoodClass, CollAdmin)
admin.site.register(Collection, CollectionAdmin)
admin.site.register(New, NewsAdmin)